memcached添加日志输出

引子:qa的memcached总是隔一段时间挂掉,导致qa进不去。决定查一下原因,于是添加日志输出,等下次出错便于查阅、定位问题。

memcache默认没有日志输出。如果想把memecache服务日志保存到日志文件中,需要在启动参数中进行配置。

安装memache后,可以通过-h来查看支持的参数,其中关于日志输出的有以下三个:

-v    verbose (print errors/warnings while in event loop)       #代表打印普通的错误或者警告类型的日志信息
-vv   very verbose (also print client commands/reponses)        #打印的日志更详细,除了错误和警告,还包含了客户端命令和server端的响应信息
-vvv  extremely verbose (also print internal state transitions) #最详尽的,甚至包含了内部的状态信息打印

根据需要选择相应的参数即可,这里选择-vv。由于需要将日志保存到文件而不是打印在控制台上,所以需要对-vv的输出进行数据流重定向。

修改memecache的脚本为:

killall memcached ; memcached -d start -m 128 -p 11211 -u root -vv >> /data/logs/mem.log.`date +%Y%m%d` 2>&1 

标蓝部分是修改部分。

>> 追加形式写入日志文件中 (>表示覆盖)
/data/logs/mem.log.`date +%Y%m%d`为日志文件的名字。以年月日作为后缀来区分,无法进行日志切分(待研究和总结),只有重启的时候才会创建新的日志文件。
2>&1 将错误信息也一同写入日志文件中(详情参考 shell输入/输出重定向)

 

重启memcache, 相应目录便生成日志文件。

slab class   1: chunk size        96 perslab   10922
slab class   2: chunk size       120 perslab    8738
slab class   3: chunk size       152 perslab    6898
slab class   4: chunk size       192 perslab    5461
slab class   5: chunk size       240 perslab    4369
slab class   6: chunk size       304 perslab    3449
slab class   7: chunk size       384 perslab    2730
slab class   8: chunk size       480 perslab    2184
slab class   9: chunk size       600 perslab    1747
slab class  10: chunk size       752 perslab    1394
slab class  11: chunk size       944 perslab    1110
slab class  12: chunk size      1184 perslab     885
slab class  13: chunk size      1480 perslab     708
slab class  14: chunk size      1856 perslab     564
slab class  15: chunk size      2320 perslab     451
slab class  16: chunk size      2904 perslab     361
slab class  17: chunk size      3632 perslab     288
slab class  18: chunk size      4544 perslab     230
slab class  19: chunk size      5680 perslab     184
slab class  20: chunk size      7104 perslab     147
slab class  21: chunk size      8880 perslab     118
slab class  22: chunk size     11104 perslab      94
slab class  23: chunk size     13880 perslab      75
slab class  24: chunk size     17352 perslab      60
slab class  25: chunk size     21696 perslab      48
slab class  26: chunk size     27120 perslab      38
slab class  27: chunk size     33904 perslab      30
slab class  28: chunk size     42384 perslab      24
slab class  29: chunk size     52984 perslab      19
slab class  30: chunk size     66232 perslab      15
slab class  31: chunk size     82792 perslab      12
slab class  32: chunk size    103496 perslab      10
slab class  33: chunk size    129376 perslab       8
slab class  34: chunk size    161720 perslab       6
slab class  35: chunk size    202152 perslab       5
slab class  36: chunk size    252696 perslab       4
slab class  37: chunk size    315872 perslab       3
slab class  38: chunk size    394840 perslab       2
slab class  39: chunk size    493552 perslab       2
slab class  40: chunk size    616944 perslab       1
slab class  41: chunk size    771184 perslab       1
slab class  42: chunk size   1048576 perslab       1
<26 server listening (auto-negotiate)
<27 server listening (auto-negotiate)
<28 send buffer was 124928, now 268435456
<32 send buffer was 124928, now 268435456
<28 server listening (udp)
<31 server listening (udp)
<30 server listening (udp)
<29 server listening (udp)
<32 server listening (udp)
<35 server listening (udp)
<34 server listening (udp)
<33 server listening (udp)
<36 new auto-negotiating client connection
36: Client using the ascii protocol
<36 set facebook_req_usrconf.do__1383 0 7200 15
>36 STORED
<37 new auto-negotiating client connection
<38 new auto-negotiating client connection
38: Client using the ascii protocol
<38 set facebook_sess_383 0 86400 8
>38 STORED
<38 get facebook_sess_383
>38 sending key facebook_sess_383
>38 END
37: Client using the ascii protocol
<37 incr facebook_add_action_t_383_usrconf.do 1
>37 NOT_FOUND
<37 set facebook_add_action_t_383_usrconf.do 0 32505 1
>37 STORED
<38 incr facebook_add_action_t2_383 1
>38 NOT_FOUND
<36 set facebook_decorate_expire_1487865600001383 512 86400 1
>36 STORED
<36 get facebook_login_mark_time_of_current
>36 END
<37 get facebook_login_mark_time_of_current
>37 END
<38 delete facebook__avas1_383

 

posted @ 2017-02-24 19:24  smily要开心  阅读(4863)  评论(2编辑  收藏  举报